package nc.ui.med.mcm.splx.splcd;

import nc.ui.pub.beans.table.VOTableModel;
import nc.vo.med.mcm.splx.PipeiVO;
import nc.vo.pub.ValueObject;

public class TbModel extends VOTableModel {

	private String[] cols = null;
	
	public TbModel(Class c,String[] cols) {
		super(c);
		setColumns(cols);
	}

	public TbModel(ValueObject vo,String[] cols) {
		super(vo);
		setColumns(cols);
	}

	public TbModel(ValueObject[] vos,String[] cols) {
		super(vos);
		setColumns(cols);
	}
	
	public String[] getColumns(){
		if(cols == null){
			cols = new String[]{""};
		}
		return cols;
	}
	
	public void setColumns(String[] cols){
		this.cols = cols;
	}

	@Override
	public String getColumnName(int col) {
		return getColumns()[col];
	}

	public int getColumnCount() {
		return getColumns().length;
	}

	public boolean isCellEditable(int row, int col) {
		return false;
	}

	public Class getColumnClass(int col) {
		return String.class;
	}

	public void setValueAt(Object obj, int row, int col) {
		PipeiVO vo = (PipeiVO) getVO(row);
		switch (col) {
			case 0:
				vo.setCol_1(obj == null ? null:obj.toString());
				break;
			case 1:
				vo.setCol_2(obj == null ? null:obj.toString());
				break;
			case 2:
				vo.setCol_3(obj == null ? null:obj.toString());
				break;
			case 3:
				vo.setCol_4(obj == null ? null:obj.toString());
				break;
			case 4:
				vo.setCol_5(obj == null ? null:obj.toString());
				break;
			case 5:
				vo.setCol_6(obj == null ? null:obj.toString());
				break;
			case 6:
				vo.setCol_7(obj == null ? null:obj.toString());
				break;
			case 7:
				vo.setCol_8(obj == null ? null:obj.toString());
				break;
			case 8:
				vo.setCol_9(obj == null ? null:obj.toString());
				break;
			case 9:
				vo.setCol_10(obj == null ? null:obj.toString());
				break;
			
		}
		fireTableCellUpdated(row, col);
	}

	public Object getValueAt(int row, int column) {
		PipeiVO vo = (PipeiVO) getVO(row);
		if (vo != null){
			switch (column) {
				case 0:
					return vo.getCol_1();
				case 1:
					return vo.getCol_2();
				case 2:
					return vo.getCol_3();
				case 3:
					return vo.getCol_4();
				case 4:
					return vo.getCol_5();
				case 5:
					return vo.getCol_6();
				case 6:
					return vo.getCol_7();
				case 7:
					return vo.getCol_8();
				case 8:
					return vo.getCol_9();
				case 9:
					return vo.getCol_10();
			}
		}
		return "";
	}
	
}
